/*

    This file is part of Hometree.

    Hometree is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Hometree is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Hometree.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2011,2012 Roman Held

*/
/********************************************************************\
                            Includes
\********************************************************************/
#include <iostream>
#include <QDateTime>
#include <QDebug>
#include "htr/htrpersistentservice.h"

/********************************************************************\
                          Global Variables
\********************************************************************/

/********************************************************************\
                            Macros
\********************************************************************/

/********************************************************************\
                          Implementation
\********************************************************************/
/*--------------------------------------------------------------------
*/
HtrPersistentService::HtrPersistentService(const QString &name, QObject *parent)
 : QObject(parent)
{
  Q_ASSERT(name.length() > 0);
  mName = name;
}

/*--------------------------------------------------------------------
*/
QString HtrPersistentService::name() const
{
  return mName;
}

/*--------------------------------------------------------------------
*/
void HtrPersistentService::addFactory(QMetaObject factory)
{
  mFactories.insert(factory.className(),factory);
}

/*--------------------------------------------------------------------
*/
QObject *HtrPersistentService::create(const QString &className)
{
  if (mFactories.contains(className)) {
    QObject *obj = mFactories[className].newInstance();
    Q_ASSERT(obj);
    return obj;
  }
  return NULL;
}
